<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h1>修改商品页面</h1>
<div>
    <input type="text" v-model="p.id">
    <input type="text" v-model="p.title">
    <input type="text" v-model="p.price">
    <input type="text" v-model="p.num">
    <input type="button" value="修改" @click="update()">
</div>
<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<script>
    let v = new Vue({
        el: "body>div",
        data: {
            p: {id: "", title: "", price: "", num: ""}
        },
        methods: {
            update(){
                //发出修改请求
                axios.post("/update",v.p).then(function () {
                    alert("修改完成!");
                    location.href="/list.html"; //显示列表页面
                })
            }
        },
        created:function () {
            //location.search得到当前浏览器地址栏中?以及后面的参数  ?id=3
            axios.get("/selectById"+location.search).then(function (response) {
                //得到服务器响应的商品对象(Java),服务器端会将Java对象转成JSON字符串
                //axios框架会将JSON字符串转成JS对象
                v.p = response.data;
            })
        }
    })
</script>
</body>
</html>